﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Globalization;
using System.Collections.Generic;
using WindowsFormsApplication1.QLSVEntities;

namespace WindowsFormsApplication1.QLSVData
{
    public class UserDAO : BaseDAO
    {
        public UserDAO()
        {

        }
        private User CreateUserFromReader(IDataReader reader)
        {
            User user = new User();
            user.Userid = (int)reader["UserID"];
            user.Username = (string)reader["Username"];
            user.Password = (string)reader["Password"];
            user.PQ = (int)reader["Mod"];
            user.Hint = (string)reader["Hint"];
            return user;
        }
        public int CheckLogin(User User)
        {
            using (SqlConnection connection = ConnectionData())
            {
                SqlCommand cmd;
                int kq;
                cmd = new SqlCommand();
                cmd.CommandText = "Login";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Connection = connection;
                cmd.Parameters.AddWithValue("@Username", User.Username);
                cmd.Parameters.AddWithValue("@Password", User.Password);
                SqlParameter returnvalue = new SqlParameter("@ACTI", "");
                returnvalue.Direction = ParameterDirection.ReturnValue;
                cmd.Parameters.Add(returnvalue);
                cmd.ExecuteNonQuery();
                kq = Convert.ToInt32(returnvalue.Value);
                connection.Close();
                return kq;
            }
        }
        //public void ChangePass(User User)
        //{
        //    using (SqlConnection connection = ConnectionData())
        //    {
        //        SqlCommand cmd;
        //        cmd = new SqlCommand();
        //        cmd.CommandText = "spUserDoipass";
        //        cmd.CommandType = CommandType.StoredProcedure;
        //        cmd.Connection = connection;
        //        connection.Open();
        //        cmd.Parameters.AddWithValue("@Username", User.Username);
        //        cmd.Parameters.AddWithValue("@Password1", User.Password);
        //        cmd.Parameters.AddWithValue("@Password2", User.Email);
        //        cmd.ExecuteNonQuery();
        //        connection.Close();
        //    }
        //}
    }
}
